/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.uniminuto.Videominuto.entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author JULIAN
 */
@Entity
@Table(name = "historial")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Historial.findAll", query = "SELECT h FROM Historial h"),
    @NamedQuery(name = "Historial.findByIdCliente", query = "SELECT h FROM Historial h WHERE h.historialPK.idCliente = :idCliente"),
    @NamedQuery(name = "Historial.findByIsanVdi", query = "SELECT h FROM Historial h WHERE h.historialPK.isanVdi = :isanVdi"),
    @NamedQuery(name = "Historial.findByFecha", query = "SELECT h FROM Historial h WHERE h.fecha = :fecha")})
public class Historial implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected HistorialPK historialPK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "fecha")
    @Temporal(TemporalType.DATE)
    private Date fecha;
    @JoinColumn(name = "isan_vdi", referencedColumnName = "isan_video", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Video video;
    @JoinColumn(name = "id_cliente", referencedColumnName = "id_cliente", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Cliente cliente;

    public Historial() {
    }

    public Historial(HistorialPK historialPK) {
        this.historialPK = historialPK;
    }

    public Historial(HistorialPK historialPK, Date fecha) {
        this.historialPK = historialPK;
        this.fecha = fecha;
    }

    public Historial(String idCliente, int isanVdi) {
        this.historialPK = new HistorialPK(idCliente, isanVdi);
    }

    public HistorialPK getHistorialPK() {
        return historialPK;
    }

    public void setHistorialPK(HistorialPK historialPK) {
        this.historialPK = historialPK;
    }

    public Date getFecha() {
        return fecha;
    }

    public void setFecha(Date fecha) {
        this.fecha = fecha;
    }

    public Video getVideo() {
        return video;
    }

    public void setVideo(Video video) {
        this.video = video;
    }

    public Cliente getCliente() {
        return cliente;
    }

    public void setCliente(Cliente cliente) {
        this.cliente = cliente;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (historialPK != null ? historialPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Historial)) {
            return false;
        }
        Historial other = (Historial) object;
        if ((this.historialPK == null && other.historialPK != null) || (this.historialPK != null && !this.historialPK.equals(other.historialPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "co.edu.uniminuto.Videominuto.entities.Historial[ historialPK=" + historialPK + " ]";
    }
    
}
